package com.anssy.voteballot.utils;

import android.content.Context;
import android.util.TypedValue;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public
/**
 * @author jackyChou
 * @date 2020/12/29
 */
class UIUtil {

    /**
     * 获取屏幕高度(px)
     */
    public static int getScreenHeight(Context context) {
        return context.getResources().getDisplayMetrics().heightPixels;
    }

    /**
     * 获取屏幕宽度(px)
     */
    public static int getScreenWidth(Context context) {
        return context.getResources().getDisplayMetrics().widthPixels;
    }

    public static float dp2px(Context context, float dp) {
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
    }

    public static float px2dp(Context context, float px) {
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, px, context.getResources().getDisplayMetrics());
    }

    /**
     * 获取屏幕宽度/2.5  16:9
     *
     * @param context
     * @return
     */
    public static LinearLayout.LayoutParams getImgWidthHeight(Context context) {

        int width = getScreenWidth(context);
        int imageWidth = (int) (width / 2.3);
        float scale = 16f / 9f;
        int imageHeight = (int) (imageWidth / scale);

        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(imageWidth, imageHeight);
        return layoutParams;
    }

    /**
     * 获取屏幕宽度16:9
     *
     * @param context
     * @return
     */
    public static LinearLayout.LayoutParams getFullWidthLayoutParams(Context context) {

        int imageWidth = getScreenWidth(context);
        float scale = 16f / 9f;
        int imageHeight = (int) (imageWidth / scale);

        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(imageWidth, imageHeight);
        return layoutParams;
    }

    public static LinearLayout.LayoutParams getHalfWidthLayoutParams(Context context) {
        int width = getScreenWidth(context);
        int imageWidth = (int) (width / 2.15);
        float scale = 16f / 9f;
        int imageHeight = (int) (imageWidth / scale);

        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(imageWidth, imageHeight);
        return layoutParams;
    }

    /**
     * 获取屏幕宽度16:9
     *
     * @param context
     * @return
     */
    public static RelativeLayout.LayoutParams getRLFullWidthHeight(Context context) {
        int imageWidth = getScreenWidth(context);
        float scale = 16f / 9f;
        int imageHeight = (int) (imageWidth / scale);

        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(imageWidth, imageHeight);
        return layoutParams;
    }


    public static LinearLayout.LayoutParams getBannerLayoutParams(Context context) {

        int padding = 5;
        int spacePx = (int) (UIUtil.dp2px(context, padding) * 2);

        int imageWidth = getScreenWidth(context) - spacePx;
        float scale = 16f / 9f;
        int imageHeight = (int) (imageWidth / scale);

        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(imageWidth, imageHeight);
        return layoutParams;
    }

}
